package com._4pd.demo.formal;

import com._4pd.demo.demo.crd.AiOperator;
import com._4pd.demo.formal.watcher.ResourceWatcher;
import io.fabric8.kubernetes.api.model.APIResource;
import io.fabric8.kubernetes.api.model.GenericKubernetesResource;
import io.fabric8.kubernetes.api.model.GenericKubernetesResourceList;
import io.fabric8.kubernetes.client.*;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.kubernetes.client.dsl.base.ResourceDefinitionContext;

import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.UnaryOperator;

public class K8sClient {
    private KubernetesClient client = new KubernetesClientBuilder().build();
    private ConcurrentHashMap<String,Watcher> resource = new ConcurrentHashMap<>();


    public KubernetesClient getClient(){
        return this.client;
    }

    public void registerWatcher(Class clazz ,Watcher watcher){
        client.resources(clazz).watch(watcher);
        //client.genericKubernetesResources(ResourceDefinitionContext.fromResourceType(clazz)).watch(watcher);
    }

    public void registerResourceWatcher(String apiVersion,String kind) throws IOException {
        client.genericKubernetesResources(apiVersion, kind).inNamespace("airflow").watch(new ResourceWatcher(this));
    }
}
